package setprite;

import java.util.Comparator;
import java.util.TreeSet;

public class Set06 {
    public static void main(String[] args) {
        //练习
        //输入四个字符串"e" "rr" "ttt" "www"按照长度进行排序，如果一样长进行首字母排序
        TreeSet<String> treeSet = new TreeSet<>((new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int result = o1.length() - o2.length();
                result = result == 0 ? o1.compareTo(o2) : result;
                return result;
            }
        }));

        treeSet.add("e");
        treeSet.add("rr");
        treeSet.add("ttt");
        treeSet.add("www");
        System.out.println(treeSet);

    }
}
